package cn.com.homeyoda.aimate.aihealth.ui.my.family.manage;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wzq.mvvmsmart.utils.GlideLoadUtils;

import java.util.ArrayList;
import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.PromptUserListBean;

public class AddMemberAdapter extends BaseQuickAdapter<PromptUserListBean.RowsBean, BaseViewHolder> {

    private final List<String> selectedUsers = new ArrayList<>();

    public AddMemberAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, PromptUserListBean.RowsBean item) {
        ImageView ivAvatar = helper.getView(R.id.iv_member_avatar);
        GlideLoadUtils.loadImg(ivAvatar, item.getAvatar(), R.mipmap.ic_member1);
        helper.setText(R.id.tv_member_name, item.getName());
        helper.setText(R.id.tv_member_age, item.getAge());
        helper.setText(R.id.tv_member_gender, item.getSex());

        ConstraintLayout clRoot = helper.getView(R.id.cl_member_item_root);
        clRoot.setSelected(selectedUsers.contains(item.getFaceId()));
    }

    public void setSelected(int position, String faceId) {
        if (selectedUsers.contains(faceId)) {
            selectedUsers.remove(faceId);
        } else {
            selectedUsers.add(faceId);
        }
        notifyItemChanged(position);
    }

    public List<String> getSelectedUsers() {
        return selectedUsers;
    }
}
